/**
 * 
 */
package gameMiniGames;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * @author Logical Solutions
 *
 */
public class StopWatch extends JLabel implements MouseListener {
	   private long startTime;
	   private boolean running; 
	   public StopWatch(){     
	      super("  Click to start timer.  ", JLabel.CENTER);   
	      addMouseListener(this);   
	   }
	   public StopWatch(JFrame frame){}	      
	   public void mousePressed(MouseEvent event) {    
	      if (running == false) {  
	         running = true;   
	         startTime = event.getWhen();  
	         setText("Timing....");   
	      }   
	      else {   
	            // Stop the timer.  Compute the elapsed time since the   
	            // timer was started and display it.   
	         running = false;   
	         long endTime = event.getWhen();   
	         double seconds = (endTime - startTime) / 1000.0;   
	         setText("Time: " + seconds + " sec.");   
	      }   
	   }   
	   public void mouseReleased(MouseEvent evt){}   
	   public void mouseClicked(MouseEvent evt){}   
	   public void mouseEntered(MouseEvent evt){}   
	   public void mouseExited(MouseEvent evt){}   
}  